// *****************************************************
// Aitrox Information Technology
// http://www.proxima-ai.com
// Copyright 2021 Aitrox. All rights reserved.
//
// Filename: download.go
// CreateDate: 2023-06-07
// Author: zjp
// Description: 下载相关数据库操作
// ******************************************************
package dao

import (
	"fmt"
	"usplatformserver/internal/model"
)

/**
 * @brief 通过检查部位获取待下载文件总数
 * @param organType-检查部位
 * @return 用户ID，错误信息
 */
func (d *Dao) GetWaitDownloadCount(organType int) (int, error) {
	return model.GetWaitDownloadCount(d.engine, organType)
}

func (d *Dao) GetWaitDownloadTypeCount() ([]*model.WaitDownloadCount, error) {
	return model.GetWaitDownloadTypeCount(d.engine)
}

/**
 * @brief 通过检查部位获取下载文件信息
 * @param organType-检查部位
 * @return 检查文件信息列表，错误信息
 */
func (d *Dao) GetDownloadFileList(organType int) ([]*model.Download, error) {
	return model.List(d.engine, organType)
}

/**
 * @brief 插入数据
 * @param organType-检查部位
 * @param fileName-文件名
 * @return 错误信息
 */
func (d *Dao) InsertDownloadFile(organType int, fileName string) error {
	info := model.Download{
		OrganType:     organType,
		FileName:      fileName,
		DownloadTimes: 0,
	}

	return info.InsertDownloadFile(d.engine)
}

/**
 * @brief 更新下载次数
 * @param id-下载文件信息唯一ID
 * @return 错误信息
 */
func (d *Dao) UpdateDownloadTimes(id int) error {
	var info model.Download
	info.Model = &model.Model{ID: uint32(id)}
	fmt.Println("info.ID: ", info.ID)

	return info.UpdateDownloadTimes(d.engine)
}

/**
 * @brief 删除下载文件信息
 * @param organType-检查部位
 * @param fileNames-文件名列表
 * @return 受影响条数，错误信息
 */
func (d *Dao) DeleteDownloadFiles(organType int, fileNames []string) (int, error) {
	return model.DeleteDownloadFiles(d.engine, organType, fileNames)
}
